home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / mms / mms.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  4.5 KB  |  196 lines

  1. /*////////////////////////////////////////////////////////////////////////
  2. Copyright (c) 1992 Electrotechnical Laboratry (ETL)
  3.  
  4. Permission to use, copy, modify, and distribute this material 
  5. for any purpose and without fee is hereby granted, provided 
  6. that the above copyright notice and this permission notice 
  7. appear in all copies, and that the name of ETL not be 
  8. used in advertising or publicity pertaining to this 
  9. material without the specific, prior written permission 
  10. of an authorized representative of ETL.
  11. ETL MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  12. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  13. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  14. /////////////////////////////////////////////////////////////////////////
  15. Content-Type: program/C; charset=US-ASCII
  16. Program:      mms.c  (metamail server)
  17. Author:       Yutaka Sato <ysato@etl.go.jp>
  18. Description:
  19.      This is a program that allows programs to compose/decompsea
  20.      a MIME-format mail with the commands via socket.
  21. History:
  22.   v0.0  92.04.21  created a small prototype
  23.   v0.1    92.04.24  added authentication (mmsauth.c)
  24.   v0.1  92.04.29  added client interface (mmsclient.c)
  25.   v0.1  92.05.02  added a MIME parser (mmsparser.c)
  26.   v0.1  92.05.03  added a MIME viewer (mmsviewer.c)
  27.   v0.2  92.05.05  added a MIME translator (mmstransl.c)
  28.   v0.2  92.05.13  separated mms.c(main) and mmsserver.c
  29.   v0.3  92.05.19  added MIME HEADER composer/decomposer (mmsencode.c)
  30.   v0.3  92.05.20  implanted mmsencode into NNTP server (nntp/)
  31. ///////////////////////////////////////////////////////////////////////*/
  32.  
  33. char *rindex();
  34. typedef int (*IFUNCP)();
  35. #include <stdio.h>
  36.  
  37. /*//////////////////////////////////////////////////////////////////////*/
  38. MMS_E_help(ac,av,in,out)
  39.     char *av[];
  40. {
  41.     fprintf(out,"Usage: %s [ENTRY] [arguments]\n",av[0]);
  42.     fprintf(out," ENTRY:");
  43.     print_entries(out);
  44. }
  45. IFUNCP MMS_E_HELP = MMS_E_help;
  46.  
  47. MMS_E_script(ac,av,in,out)
  48.     char *av[];
  49. {    char *file;
  50.     int ai;
  51.     FILE *sfp;
  52.  
  53.     if( ac < 2 )
  54.         exit(-1);
  55.     MMS_start_server();
  56.  
  57.     for( ai = 1; ai < ac; ai++ ){
  58.         sfp = fopen(av[ai],"r");
  59.         if( sfp == NULL )
  60.             exit(-1);
  61.         MMS_server_interpreter(sfp);
  62.         fclose(sfp);
  63.     }
  64. }
  65. IFUNCP MMS_E_SCRIPT = MMS_E_script;
  66.  
  67. /*//////////////////////////////////////////////////////////////////////*/
  68. IFUNCP MMS_E_VERSION;
  69. IFUNCP MMS_E_SERVER;
  70. IFUNCP MMS_E_CLIENT;
  71. IFUNCP MMS_E_VIEWER;
  72. IFUNCP MMS_E_TRANSL;
  73. IFUNCP MMS_E_COMPOSE;
  74. IFUNCP MMS_E_ENCODEBASE16;
  75. IFUNCP MMS_E_DECODEBASE16;
  76. IFUNCP MMS_E_HEAD_ENCODER;
  77. IFUNCP MMS_E_HEAD_DECODER;
  78.  
  79. struct {
  80.     char    *e_name;
  81.     IFUNCP    *e_funcp;
  82.  
  83. } MMS_entries[] = {
  84.     {"version",    &MMS_E_VERSION},
  85.     {"help",    &MMS_E_HELP},
  86.     {"server",    &MMS_E_SERVER},
  87.     {"client",    &MMS_E_CLIENT},
  88.     {"script",    &MMS_E_SCRIPT},
  89.     {"viewer",    &MMS_E_VIEWER},
  90.     {"transl",    &MMS_E_TRANSL},
  91.     {"compose",    &MMS_E_COMPOSE},
  92.     {"encode",    &MMS_E_ENCODEBASE16},
  93.     {"decode",    &MMS_E_DECODEBASE16},
  94.     {"hencode",    &MMS_E_HEAD_ENCODER},
  95.     {"hdecode",    &MMS_E_HEAD_DECODER},
  96.     0
  97. };
  98.  
  99. int arg_infile();
  100. struct {
  101.     char    *a_name;
  102.     int     a_count;
  103.     IFUNCP     a_funcp;
  104. } MMS_argments[] = {
  105.     {"-f",    2,    arg_infile},
  106.     0
  107. };
  108.  
  109.  
  110. IFUNCP *MMS_E_default = &MMS_E_CLIENT;
  111.  
  112.  
  113. print_entries(out)
  114.     FILE *out;
  115. {    int ei;
  116.     char *name;
  117.  
  118.     for(ei = 0; name = MMS_entries[ei].e_name; ei++){
  119.         if( MMS_entries[ei].e_funcp == MMS_E_default )
  120.             fprintf(out,"\t[-%s]\n",name);
  121.         else    fprintf(out,"\t-%s\n",name);
  122.     }
  123. }
  124.  
  125. remove_arg(ac,av,delai,delcnt)
  126.     char *av[];
  127. {    int ai;
  128.  
  129.     for( ai = delai; ai < ac; ai++ )
  130.         av[ai] = av[ai+delcnt];
  131.     return ac - delcnt;
  132. }
  133.  
  134. main(ac,av)
  135.     char *av[];
  136. {    char *file_ename,*arg1_ename,*ename;
  137.     int ei;
  138.     IFUNCP efunc;
  139.     FILE *input;
  140.  
  141. /*
  142. { int ai; for(ai=0; ai<ac; ai++){ fprintf(stderr,"[%d]%s\n",ai,av[ai]); } }
  143. */
  144.  
  145.     input = stdin;
  146.     if( file_ename = rindex(av[0],'/') )
  147.         file_ename++;
  148.     else    file_ename = av[0];
  149.     if( strncmp(file_ename,"mms",3) == 0 )
  150.         file_ename += 3;
  151.  
  152.     if( 1 < ac && av[1][0] == '-' )
  153.         arg1_ename = &av[1][1];
  154.     else    arg1_ename = "";
  155.  
  156.     for(ei = 0; ename = MMS_entries[ei].e_name; ei++ ){
  157.         if( strcmp(ename,file_ename) == 0 )
  158.             break;
  159.         if( strcmp(ename,arg1_ename) == 0 ){
  160.             ac = remove_arg(ac,av,1,1);
  161.             break;
  162.         }
  163.     }
  164.     if( 2 < ac ){
  165.         if( strcmp("-f",av[1]) == 0 ){
  166.             char *file = av[2];
  167.  
  168.             ac = remove_arg(ac,av,1,2);
  169.             input = fopen(file,"r");
  170.         }
  171.     }
  172.  
  173. /*
  174. { int ai; for(ai=0; ai<ac; ai++){ fprintf(stderr,"[%d]%s\n",ai,av[ai]); } }
  175. */
  176.  
  177.  
  178.     if( ename ){
  179.         if( efunc = *MMS_entries[ei].e_funcp ){
  180.             (*efunc)(ac,av,input,stdout);
  181.         }else{
  182.             fprintf(stderr,
  183.                 "This program does not include '%s'.\n",ename);
  184.         }
  185.     }else    MMS_client(ac,av,input);
  186.  
  187.     MMS_mailtoFinalize();
  188.     return 0;
  189. }
  190.  
  191. static
  192. arg_infile(ac,av)
  193.     char *av[];
  194. {
  195. }
  196.